package com.zlyx.easy.jedis.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.zlyx.easy.asyn.interfaces.AsynMsgCustomer;
import com.zlyx.easy.asyn.supports.AbstractMsgListener;
import com.zlyx.easy.asyn.supports.AsynMsgSender;
import com.zlyx.easy.jedis.supports.JedisMsgListener;
import com.zlyx.easy.jedis.supports.JedisMsgSender;

import redis.clients.jedis.JedisPool;

@Configuration
public class JedisConfig {

	@Value("${easy.jedis.channel:easy-jedis-channel}")
	private String jedisChannelKey;

	@Bean
	@ConditionalOnBean(AsynMsgCustomer.class)
	@ConditionalOnMissingBean(AbstractMsgListener.class)
	public AbstractMsgListener configRedisMsgListener() {
		return new JedisMsgListener(jedisChannelKey);
	}

	@Bean
	@ConditionalOnClass(JedisPool.class)
	public AsynMsgSender configMsgSender() {
		return new JedisMsgSender(jedisChannelKey);
	}
}
